"""

This is used to check the url redirection
"""

import urllib2
import httplib
import socket
socket.setdefaulttimeout(10)
def get_redirected_url(old_url):
    try:
        opener = urllib2.build_opener(urllib2.HTTPRedirectHandler)
        request = opener.open(old_url)
    except urllib2.HTTPError ,e:
        return old_url
    except urllib2.URLError,e:
        return old_url
    except httplib.BadStatusLine:
        return old_url
    except:
        return old_url
           
    return request.url


#print get_redirected_url("http://www2.webkit.org/perf/sunspider-0.9/sunspider-results.html?")


"""
>>> p = re.compile( ... )
>>> iterator = p.finditer('12 drummers drumming, 11 ... 10 ...')
>>> iterator
<callable-iterator object at 0x401833ac>
>>> for match in iterator:
...     print match.span()
"""


"""
import re
    
def get_links(content):
    print "content = ", content
   # content = "href= http:\\google.com"
    #content = "http://src.chromium.org/viewvc/chrome/trunk/src/views/controls/menu/menu_controller.cc?r1=30049&r2=30048"
    p = re.compile('https?://\S+')
    iterator = p.finditer(content,0)
    for match in iterator:
        print match.span()
        print match.group()
  #  links = re.findall(r'(https?://\S+(-\n\S+)?)', content, re.I)
    
    #print links
    #return links

con = "http://dgd http://www.winsplit-\nrevolution.com/),"
get_links(con)
"""